using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Splino
{
    /// <summary>
    /// Contains a Color Dialog defined for Splino Objects
    /// </summary>
    public partial class SplinoObjectColorDialog : Component
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public SplinoObjectColorDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="container">Container</param>
        public SplinoObjectColorDialog(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="color">The color to initially display</param>
        public SplinoObjectColorDialog(Color color)
            : this()
        {
            _colorDialog.Color = color;
            _colorDialog.CustomColors = new int[] { ColorFix(color) };
        }

        /// <summary>
        /// Corrects a compatibility issue between ColorDialog.CustomColors and Color.ToArgb
        /// </summary>
        /// <param name="color">The color to fix</param>
        /// <returns>An integer for use in the CustomColors property of a ColorDialog</returns>
        public static int ColorFix(Color color)
        {
            return (color.R + (color.G << 8) + (color.B << 16));
        } 

        /// <summary>
        /// Gets or sets the color of the Color Dialog.
        /// </summary>
        public Color Color
        {
            get { return _colorDialog.Color; }
            set { _colorDialog.Color = value; }
        }

        /// <summary>
        /// Displays the Color Dialog and returns the result.
        /// </summary>
        /// <returns>The response to the dialog by the user.</returns>
        public DialogResult ShowDialog()
        {
            return _colorDialog.ShowDialog();
        }
    }
}
